package com.jt.blog.service;

import com.jt.blog.model.Comment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

/**
 * @author : 戴瑞
 * @Description :博客评论层
 * @create : 2017-06-01 13:20
 **/
@Service
@Transactional
public class CommentWriteServiceImpl extends AbstractBaseService<Comment> implements CommentWriteService {
    @Override
    public void create(Comment comment) {
        comment.setCreateTime(new Date());
        mapper.insert(comment);
    }

    @Override
    public void delete(Comment comment) {

        Example example = new Example(Comment.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("pid",comment.getId());
        List<Comment> comments = mapper.selectByExample(example);
        if (comments.size() > 0) {
            for (Comment cm : comments) {
                delete(cm);
            }
        }
        mapper.deleteByPrimaryKey(comment.getId());
    }

    @Override
    public void update(Comment comment) {

    }
}
